﻿using NeXus.BIMBase.Core;
using NeXus.BIMBase.Data;
using NeXus.BIMBase.SolidCore;
using NeXus.p3d;

namespace checc_baseTools
{
    public class Element_chain
    {
        /// <summary>
        /// 点
        /// </summary>
        /// <param name="Point">点的坐标</param>
        public static BPModelPoint Point(GePoint3d Point)
        {
            BPProject p = BPApplication.getInstance().getProjectManager().getMainProject();
            BPModelBase model = p.getActiveModel();

            BPModelPoint point = BPModelPoint.create(Point);
            point.setLineColor((uint)System.Drawing.Color.Blue.ToArgb());
            point.setLineWeight(30);
            P3DStatus ret = point.addToProject(p, model.getModelId());

            return point;
        }

        ///// <summary>
        ///// 线或线串
        ///// </summary>
        ///// <param name="Point1">第一点坐标</param>
        ///// <param name="Point2">第二点坐标</param>
        //public static BPModelLine Thread(GePoint3d Point1, GePoint3d Point2)
        //{
        //    BPDocument doc = BPApplication.singleton().activeDocument;
        //    BPModel model = doc.modelManager.activeModel;

        //    BPModelLine line = new BPModelLine(Point1, Point2);
        //    line.lineStyle = DrawingLineStyles.eContinuous;
        //    line.lineWeight = DrawingLineWeights.eW21;
        //    line.lineColor = System.Drawing.Color.Black;
        //    BIMBaseCS.BPStatus sta = line.addToDocument(model);

        //    return line;
        //}

        ///// <summary>
        ///// 圆
        ///// </summary>
        ///// <param name="center">圆心</param>
        ///// <param name="radius">半径</param>
        //public static BPModelCircle Circular(GePoint3d center, double radius)
        //{
        //    BPProject p = BIMBase.Core.BPApplication.getInstance().getProjectManager().getMainProject();
        //    BPModelBase model = p.getActiveModel();

        //    BPModelCircle circle = BPModelCircle.Create(center, v3d, 4000);
        //    BIMBaseCS.BPStatus sta = circle.addToDocument(model);

        //    return circle;
        //}

        /// <summary>
        /// 圆
        /// </summary>
        /// <param name="center">圆心</param>
        /// <param name="center">向量</param>
        /// <param name="radius">半径</param>
        public static BPModelCircle CircularByVec3d(GePoint3d center, GeVec3d normal, double radius)
        {

            BPProject p = BPApplication.getInstance().getProjectManager().getMainProject();
            BPModelBase model = p.getActiveModel();

            BPModelCircle circle = BPModelCircle.Create(center, normal, radius);
            P3DStatus sta = circle.addToModel(p, model.getModelId());

            return circle;
        }
        /// <summary>
        /// 圆弧
        /// </summary>
        /// <param name="Point1">起点</param>
        /// <param name="Point2">中间点</param>
        /// <param name="Point3">终点</param>
        public static BPModelArc3d Arc(GePoint3d Point1, GePoint3d Point2, GePoint3d Point3)
        {
            BPProject p = BPApplication.getInstance().getProjectManager().getMainProject();
            BPModelBase model = p.getActiveModel();
            //圆弧1
            BPModelArc3d arc = BPModelArc3d.Create(Point1, Point2, Point3);
            P3DStatus ret = arc.addToProject(p, model.getModelId());
            return arc;
        }

        /// <summary>
        /// 椭圆
        /// </summary>
        /// <param name="Point1">基点</param>
        /// <param name="radius1">第一个弧方位向量</param>
        /// <param name="radius2">第二个弧方位向量</param>
        public static BPModelEllipse3d Elliptical(GePoint3d Point1, GeVec3d radius1, GeVec3d radius2)
        {
            BPProject p = BPApplication.getInstance().getProjectManager().getMainProject();
            BPModelBase model = p.getActiveModel();
            BPModelEllipse3d ellipe = BPModelEllipse3d.Create(Point1, radius1, radius2);
            P3DStatus sta = ellipe.addToModel(p, model.getModelId());
            return ellipe;
        }

        /// <summary>
        /// 椭圆弧
        /// </summary>
        /// <param name="Point1">基点</param>
        /// <param name="radius1">第一个弧方位向量 </param>
        /// <param name="radius2">第二个弧方位向量 </param>
        /// <param name="startAngle">始角</param>
        /// <param name="sweepAngle">弧角</param>
        public static BPModelEllipseArc3d EllipticalArc(GePoint3d Point1, GeVec3d radius1, GeVec3d radius2, double startAngle, double sweepAngle)
        {
            BPProject p = BPApplication.getInstance().getProjectManager().getMainProject();
            BPModelBase model = p.getActiveModel();

            BPModelEllipseArc3d ellipearc = BPModelEllipseArc3d.Create(Point1, radius1, radius2, startAngle, sweepAngle);
            P3DStatus sta = ellipearc.addToModel(p, model.getModelId());

            return ellipearc;
        }

        ///// <summary>
        ///// 放样线
        ///// </summary>
        ///// <param name="points">控制点集合</param>
        ///// <param name="points1">放样线离散点集合</param>
        ///// <param name="order">弧线顺序</param>
        ///// <param name="discreteNum">离散数</param>
        //public static IGeCurveBase LoftingLine(GePoint3dCollection points, int order, int discreteNum)
        //{
        //    BPProject p = BPApplication.getInstance().getProjectManager().getActiveProject();
        //    BPModelBase model = p.getActiveModel();

        //    GeTransform form = GeTransform.createIdentityMatrix();
        //    GePoint3dCollection a = new GePoint3dCollection();
        //    bool curve = BPCurveApproximationFunction.createGeBsplinePoints(points, a, order, discreteNum);

        //    BPGraphics graphic = new BPGraphics(model);
        //    graphic.addCurve(curve);
        //    graphic.save();

        //    return curve;
        //}

        ///// <summary>
        ///// 螺旋线
        ///// </summary>
        ///// <param name="points">螺旋线离散点集合</param>
        ///// <param name="startRadians">开始旋转角度</param>
        ///// <param name="endRadians">结束旋转角度</param>
        ///// <param name="startRadius">开始半径</param>
        ///// <param name="endRadius">结束半径</param>
        ///// <param name="discreteNum">离散数</param>
        ///// <param name="isVerz">是否z方向离散</param>
        ///// <param name="VerZHeight">z轴离散</param>
        //public static IGeCurveBase SpiralLine(List<GePoint3d> points, double startRadians, double endRadians, double startRadius, double endRadius, int discreteNum, bool isVerz, double VerZHeight)
        //{
        //    BPProject project = BIMBase.Core.BPApplication.getInstance().getProjectManager().getMainProject();
        //    BPModelBase model = project.getActiveModel();
        //    GePoint3dCollection pointPvecs = new GePoint3dCollection();
        //    foreach (var item in points)
        //    {
        //        pointPvecs.Add(item);
        //    }
        //    GePoint3dCollection points1 = new GePoint3dCollection();
        //    var curve = BPCurveApproximationFunction.createGeBsplinePoints(points1, pointPvecs, startRadius, endRadians, endRadius, discreteNum, isVerz, VerZHeight);
        //    BPGraphics graphicTemp = new BPGraphics(model);
        //    graphicTemp.addCurve(curve);
        //    graphicTemp.save();

        //    return curve;
        //}
    }
}
